Skip to content

fix(FOUR-34369): eager-load processRequest.process in optimized index… - #9157

Merged
pmPaulis merged 32 commits into
nightly/2026.17-perfomancefrom
bugfix/FOUR-34369
Nov 13, 2026
Merged

pmPaulis merged 32 commits into
nightly/2026.17-perfomancefrom
bugfix/FOUR-34369

Conversation

@gproly

@gproly gproly commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

… query

Register constrained with() for processRequest.process when the client requests that include on indexOptimizedBaseQuery. It was listed in handledIncludes but never applied, so the nested process was missing or lazy-loaded per row.

https://processmaker.atlassian.net/browse/FOUR-34369

ci:screen-builder:v3.8.43-branch-5932fbd7
ci:vue-form-elements:v0.65.11-branch-2c6a640

… query

Register constrained with() for processRequest.process when the client
requests that include on indexOptimizedBaseQuery. It was listed in
handledIncludes but never applied, so the nested process was missing or
lazy-loaded per row.

https://processmaker.atlassian.net/browse/FOUR-34369
@cursor

cursor Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

PR Summary

High Risk
Changes task API authorization and data exposure for drafts across index/show paths; incorrect redaction would leak assignee draft data or break includes.

Overview
This PR tightens task draft handling on task list/show APIs: drafts are only eager-loaded when include asks for them, and responses are sanitized so draft data is visible only to assignees, process managers, or others who pass task view checks— including nested includes like processRequest.tokens.draft and Laravel-style draft:* tokens. A new TaskDraftIncludes helper centralizes include parsing and constrained eager loads; legacy/optimized index paths stop always loading draft and add missing optimized eager loads (e.g. processRequest.process).

Related fixes: raw token/request persistence now triggers Scout index sync after SQL updates; v1.1 task completion checks authorization before rejecting already-closed tasks; v1.1 optimized index passes managed-process visibility resolution into applyProcessManager. Feature tests cover draft redaction, drafts-disabled consume behavior, and fast-show paths.

Reviewed by Cursor Bugbot for commit f43c706. Bugbot is set up for automated code reviews on this repo. Configure here.

Raw UPDATEs in TokenPersistenceRawRepository bypass Eloquent save(), so
Scout never ran when TOKEN_PERSISTENCE_RAW_ENABLED was on. Invoke
ModelObserver::saved after token and process request raw updates so
indexed search stays in sync on activate/complete.

https://processmaker.atlassian.net/browse/FOUR-34369
indexOptimizedBaseQuery used process_request_token_id and uuid on TaskDraft,
but drafts are keyed by task_id and the table has no uuid column. Align the
include with TaskResource and show-fast: id, task_id, data.

https://processmaker.atlassian.net/browse/FOUR-34369
With TASK_UPDATE_V1_1_ENABLED, PUT /api/1.1/tasks/{id} returned 422 for
another user's CLOSED tasks before Gate::authorize, leaking closed state.
Run the update policy first to match v1.0 and return 403 for unauthorized
callers on both open and closed tasks.

https://processmaker.atlassian.net/browse/FOUR-34369
Restore version and package-savedsearch constraint to match origin/develop,
reverting local branch overrides.

https://processmaker.atlassian.net/browse/FOUR-34369
…ager loads

Extract helpers for include parsing and optimized with() building so
indexOptimizedBaseQuery satisfies Sonar S3776 without changing query
behavior.

https://processmaker.atlassian.net/browse/FOUR-34369
@gproly
gproly requested a review from rodriquelca November 11, 2026 21:21
@cursor
cursor Bot requested a review from nolanpro November 12, 2026 12:19
…sion

Eager-load task drafts without data on the optimized index and gate
includeDraft on ProcessRequestTokenPolicy::view so view-all_requests
cannot read other assignees' unsubmitted form data via include=draft.
…sion

Eager-load task drafts without data on the optimized index and gate
includeDraft on ProcessRequestTokenPolicy::view so view-all_requests
cannot read other assignees' unsubmitted form data via include=draft.

https://processmaker.atlassian.net/browse/FOUR-34369

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…ctions

ProcessRequestTokenPolicy::view needs user_id and process.manager_id; the
optimized index and fast show omit them. Load missing attributes before
gating draft.data, and eager-load manager_id when include=draft.

https://processmaker.atlassian.net/browse/FOUR-34369

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Omit draft payloads for list callers without task view rights; eager-load
draft without data on the optimized index. Resolve manager checks from
process.properties (not a DB column), avoid attaching process on
draft-only includes, and hydrate partial tokens for assignee/self-service
policy checks without leaking process config in list JSON.

https://processmaker.atlassian.net/browse/FOUR-34369

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Match ProcessRequestTokenPolicy::view when manager_id values in
process properties are stored as strings.

https://processmaker.atlassian.net/browse/FOUR-34369
Load manager IDs from a targeted properties query for draft gating instead
of selecting properties onto the task process relation in showFast and
the optimized task index.

https://processmaker.atlassian.net/browse/FOUR-34369

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Agentic Security Review — 2 finding(s).

  • [MEDIUM] ProcessMaker/Traits/TaskControllerIndexMethods.php:96 — Draft payload redaction runs only when the include list contains the exact token "draft". On the default optimized task index, any other include path that eager-loads the draft relation (for example include=draft.processRequestToken or include=draft.media) is forwarded to Eloquent with(), loads the full TaskDraft row, and is emitted by Task::toArray via the model relation array because includeDraft() never runs. A caller who can list tasks but fails ProcessRequestTokenPolicy::view therefore receives another assignee's draft.data.

    • Impact: view-all_requests is a list permission, not task view. It is on the seeded Requesters group, and GET /api/1.0/tasks has no can:view middleware. applyForCurrentUser returns every task for that permission, while ProcessRequestTokenPolicy::view still withholds the task from non-assignees, non-managers, and non-self-service users. The new index test treats another assignee's in-progress form draft as data those callers must not receive. The nested-include bypass returns that JSON, including form fields the assignee has not submitted. Users without view-all_requests stay limited to their own and self-service tasks, and administrators are allowed to see drafts. With OPTIMIZED_TASKS_ENABLED=false the same hole is wider: indexBaseQuery always eager-loads an unconstrained draft, so an omitted include also embeds draft.data because includeDraft() is never called.
    • Remediation: Apply the draft visibility filter whenever the draft relation is loaded, not only for the exact include token draft. Do not pass caller-supplied include paths that eager-load draft or draft.* around that filter; constrain or reject those paths. On the non-optimized index, stop unconditionally eager-loading the full draft row, or run the same redaction on any loaded draft before the task resource serializes relations. Keep the authorized re-query of data only after userCanViewTaskForDraft succeeds.
  • [MEDIUM] ProcessMaker/Traits/TaskResourceIncludes.php:68 — GET /api/1.0/tasks?include=draft now hydrates other assignees' TaskDraft rows on the default optimized index. When app.task_drafts_enabled is false, includeDraft calls $draft->delete() before the new userCanViewTaskForDraft check, so a view-all_requests user who can list tasks but fails ProcessRequestTokenPolicy::view deletes those drafts.

    • Impact: A normal authenticated user in the seeded Requesters role (view-all_requests only) can page through tasks they are not allowed to view and permanently delete other assignees' task_drafts rows, including the in-progress data JSON. TaskDraft uses Spatie HasMedia and model delete fires delete events (TaskDraftController relies on that); associated draft uploads are removed with the row. The same PR treats this caller as unauthorized for the draft payload and returns only id and task_id when drafts are enabled, so the disabled-draft branch is a cross-user integrity bypass of that boundary. The response is still 200 with draft:null.
    • Remediation: Run userCanViewTaskForDraft (after ensureTokenAttributesForViewPolicy) before $draft->delete(). If the caller is unauthenticated or fails the view check, return draft:null and leave the row in place. Keep disabled-draft cleanup only for callers who pass ProcessRequestTokenPolicy::view. Add a test with task_drafts_enabled false asserting a view-all_requests caller does not remove another assignee's task_drafts row or its media.

Use TaskDraftIncludes for v1.1 preprocessInclude/fromTokenWithIncludes and
load the draft relation only for exact include=draft, not draft.* tokens.

https://processmaker.atlassian.net/browse/FOUR-34369
…ates

Include the helper referenced by task index and task resources for parsing
include=draft tokens, constrained eager loads, and draft.* filtering.

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

isDraftToken no longer uses str_contains('.draft'), which falsely blocked
includes such as processRequest.draftApproval. Treat draft only when the
token is draft, starts with draft., ends with .draft, or contains a .draft.
segment so nested draft paths stay gated without dropping unrelated includes.

https://processmaker.atlassian.net/browse/FOUR-34369
Apply draft visibility on any loaded draft payload (including draft.*-style
includes), tighten optimized additionalIncludes filtering, and add legacy
draft.media and disabled-draft media regression tests.

https://processmaker.atlassian.net/browse/FOUR-34369

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Redact nested drafts only under tokens lists, load tokens and drafts from
the database with task_id constraints, and ignore planted id/draft objects
in request_data.

https://processmaker.atlassian.net/browse/FOUR-34369
Honor includesDraft on show (omit fast-path preloads without include, resolve
when requested). Bind draft policy to persisted tokens and task_id-scoped rows;
redact nested drafts only under tokens, not request_data. Tighten optimized
index filters and add show/plant/disabled-draft regression tests.

https://processmaker.atlassian.net/browse/FOUR-34369
@gproly gproly closed this Nov 12, 2026
@gproly gproly reopened this Nov 12, 2026
Normalize draft segment detection so mixed-case includes cannot bypass
eager-load filters or sanitize/redaction on nested token drafts.

https://processmaker.atlassian.net/browse/FOUR-34369
Split resolveDraftPayloadForToken for Sonar S1142 and extract draftIdFromPayload
to clear nested ternary S3358 without changing draft authorization behavior.

https://processmaker.atlassian.net/browse/FOUR-34369
Passing null into applyProcessIndexPmql triggered a TypeError after the
Sonar refactor added a string type hint; normalize pmql before the call.

https://processmaker.atlassian.net/browse/FOUR-34369

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

… includes

Nested draft includes (e.g. processRequest.tokens.draft) no longer eager-load,
resolve, or delete the parent task draft when only nested paths are requested.
Root draft.* includes still use constrained eager load with nested relations (draft.media).

https://processmaker.atlassian.net/browse/FOUR-34369

@cursor cursor Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

… parsing

Strip :* and :col from include paths so nested draft eager loads and
sanitization apply to processRequest.tokens.draft:* variants; redact nested
drafts defensively when serialized token trees contain draft payloads.

https://processmaker.atlassian.net/browse/FOUR-3436fix(FOUR-34369): treat Laravel include column suffixes in draft token parsing

Strip :* and :col from include paths so nested draft eager loads and
sanitization apply to processRequest.tokens.draft:* variants; redact nested
drafts defensively when serialized token trees contain draft payloads.

https://processmaker.atlassian.net/browse/FOUR-343699
… disabled

Nested draft redaction suppresses payload without deleting rows; root include=draft
retains legacy delete-on-access for assignees.

https://processmaker.atlassian.net/browse/FOUR-34369
…e drafts for managers

When task drafts are disabled, process managers listing with
processRequest.tokens.draft must not remove other assignees' task_drafts rows.

https://processmaker.atlassian.net/browse/FOUR-34369
Avoid per-row token queries on optimized index when draft is included;
prefetch nested token rows for redaction and cache process manager ids.

https://processmaker.atlassian.net/browse/FOUR-34369
cursor[bot]

This comment was marked as resolved.

@pmPaulis
pmPaulis self-requested a review November 13, 2026 03:18
…o assignee

Reject serialized token policy fields, require authoritative attrs on root
resource, and avoid deleting assignee drafts when managers list with
include=draft while drafts are disabled.

https://processmaker.atlassian.net/browse/FOUR-34369
test(cache): enable metrics in ScreenCacheFactoryTest setUp
refactor(FOUR-34369): reduce Sonar complexity in TaskResourceIncludes

https://processmaker.atlassian.net/browse/FOUR-34369
@decisions-sonarqube

Copy link
Copy Markdown

@pmPaulis
pmPaulis merged commit 7c3ec3f into nightly/2026.17-perfomance Nov 13, 2026
17 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants